﻿using OpenCompiler.AST;
using OpenCompiler.Scanning;

namespace OpenCompiler.LanguageElements
{
	public class Modifier : ILanguageElement
	{
		public Statement Generate(Statement statement, Token[] tokens, int tokenIndex, out int tokensUsed)
		{
			var token = tokens[tokenIndex];
			if( token.ActualToken is Keyword )
			{
				switch( (Keyword)token.ActualToken )
				{
					case Keyword.PUBLIC:
						{
							ModifierState.IsPublic = true;
						}
						break;
					case Keyword.PRIVATE:
						{
							ModifierState.IsPrivate = true;
						}
						break;
					case Keyword.PROTECTED:
						{
							ModifierState.IsProtected = true;
						}
						break;
					case Keyword.INTERNAL:
						{
							ModifierState.IsInternal = true;
						}
						break;
					case Keyword.ABSTRACT:
						{
							ModifierState.IsAbstract = true;
						}
						break;
					case Keyword.VIRTUAL:
						{
							ModifierState.IsVirtual = true;
						}
						break;
					case Keyword.STATIC:
						{
							ModifierState.IsStatic = true;
						}
						break;
					case Keyword.READONLY:
						{
							ModifierState.IsReadonly = true;
						}
						break;
					case Keyword.VOLATILE:
						{
							ModifierState.IsVolatile = true;
						}
						break;
					case Keyword.UNSAFE:
						{
							ModifierState.IsUnsafe = true;
						}
						break;
					case Keyword.PARTIAL:
						{
							ModifierState.IsPartial = true;
						}
						break;
					case Keyword.SEALED:
						{
							ModifierState.IsSealed = true;
						}
						break;
					case Keyword.OVERRIDE:
						{
							ModifierState.IsOverride = true;
						}
						break;
				}
			}
			tokensUsed = 1;
			return statement;
		}
	}
}
